home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWLinShp.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  9.7 KB  |  370 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWLinShp.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWLINSHP_H
  13. #include "FWLinShp.h"
  14. #endif
  15.  
  16. #ifndef FWGRGLOB_H
  17. #include "FWGrGlob.h"
  18. #endif
  19.  
  20. #ifndef FWGC_H
  21. #include "FWGC.h"
  22. #endif
  23.  
  24. #ifndef FWINK_H
  25. #include "FWInk.h"
  26. #endif
  27.  
  28. #ifndef FWSTYLE_H
  29. #include "FWStyle.h"
  30. #endif
  31.  
  32. #ifndef FWGRUTIL_H
  33. #include "FWGrUtil.h"
  34. #endif
  35.  
  36. #ifndef FWRASTER_H
  37. #include "FWRaster.h"
  38. #endif
  39.  
  40. // ----- Foundation Includes -----
  41.  
  42. #ifndef FWSTREAM_H
  43. #include "FWStream.h"
  44. #endif
  45.  
  46. // ----- OpenDoc Includes -----
  47.  
  48. #ifndef _TRANSFORM_
  49. #include <Trnsform.xh>
  50. #endif
  51.  
  52. //========================================================================================
  53. //    RunTime Info
  54. //========================================================================================
  55.  
  56. #if FW_LIB_EXPORT_PRAGMAS
  57. #pragma lib_export on
  58. #endif
  59.  
  60. #ifdef FW_BUILD_MAC
  61. #pragma segment FWGraphics_LineShape
  62. #endif
  63.  
  64. FW_DEFINE_CLASS_M1(FW_CLineShape, FW_CShape)
  65. FW_REGISTER_ARCHIVABLE_CLASS(FW_LLineShape, FW_CLineShape, FW_CLineShape::Read, FW_CShape::Write)
  66.  
  67. //========================================================================================
  68. //    class FW_CLineShape
  69. //========================================================================================
  70.  
  71. //----------------------------------------------------------------------------------------
  72. //    FW_CLineShape::FW_CLineShape
  73. //----------------------------------------------------------------------------------------
  74.  
  75. FW_CLineShape::FW_CLineShape(const FW_CLineShape& other) :
  76.     FW_CShape(other),
  77.     fStart(other.fStart),
  78.     fEnd(other.fEnd)
  79. {
  80.     FW_END_CONSTRUCTOR
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. //    FW_CLineShape::FW_CLineShape
  85. //----------------------------------------------------------------------------------------
  86.  
  87. FW_CLineShape::FW_CLineShape() :
  88.     FW_CShape(FW_kFrame, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont)
  89.         // fStart and fEnd are initialzied to 0's by default constructors
  90. {
  91.     FW_END_CONSTRUCTOR
  92. }
  93.  
  94. //----------------------------------------------------------------------------------------
  95. //    FW_CLineShape::FW_CLineShape
  96. //----------------------------------------------------------------------------------------
  97.  
  98. FW_CLineShape::FW_CLineShape(FW_CFixed xStart, FW_CFixed yStart,
  99.                              FW_CFixed xEnd, FW_CFixed yEnd,
  100.                                const FW_PInk& ink,
  101.                                const FW_PStyle& style) :
  102.     FW_CShape(FW_kFrame, ink, style, FW_kNormalFont),
  103.     fStart(xStart, yStart),
  104.     fEnd(xEnd, yEnd)
  105. {
  106.     FW_END_CONSTRUCTOR
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. //    FW_CLineShape::FW_CLineShape
  111. //----------------------------------------------------------------------------------------
  112.  
  113. FW_CLineShape::FW_CLineShape(const FW_CPoint& start,
  114.                              const FW_CPoint& end,
  115.                                const FW_PInk& ink,
  116.                                const FW_PStyle& style) :
  117.     FW_CShape(FW_kFrame, ink, style, FW_kNormalFont),
  118.     fStart(start),
  119.     fEnd(end)
  120. {
  121.     FW_END_CONSTRUCTOR
  122. }
  123.  
  124. //----------------------------------------------------------------------------------------
  125. //    FW_CLineShape::FW_CLineShape
  126. //----------------------------------------------------------------------------------------
  127.  
  128. FW_CLineShape::FW_CLineShape(FW_CReadableStream& archive) :
  129.     FW_CShape(archive)
  130. {
  131.     archive >> fStart;
  132.     archive >> fEnd;
  133.     FW_END_CONSTRUCTOR
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. //    FW_CLineShape::~FW_CLineShape
  138. //----------------------------------------------------------------------------------------
  139.  
  140. FW_CLineShape::~FW_CLineShape()
  141. {
  142.     FW_START_DESTRUCTOR
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    FW_CLineShape::operator=
  147. //----------------------------------------------------------------------------------------
  148.  
  149. FW_CLineShape& FW_CLineShape::operator=(const FW_CLineShape& other)
  150. {
  151.     if (this != &other)
  152.     {
  153.         FW_CShape::operator=(other);
  154.     
  155.         fStart = other.fStart;
  156.         fEnd = other.fEnd;
  157.     }
  158.     
  159.     return *this;
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    FW_CLineShape::Render
  164. //----------------------------------------------------------------------------------------
  165.  
  166. void FW_CLineShape::Render(FW_CGraphicContext& gc) const
  167. {
  168.     gc.GetRasterizer()->RenderLine(gc,
  169.                                     fStart, fEnd,
  170.                                     GetRenderVerb(),
  171.                                     fInk,
  172.                                     fStyle);
  173. }
  174.  
  175. //----------------------------------------------------------------------------------------
  176. //    FW_CLineShape::RenderLine
  177. //----------------------------------------------------------------------------------------
  178.  
  179. void FW_CLineShape::RenderLine(FW_CGraphicContext& gc,
  180.                                 const FW_CPoint& start, 
  181.                                 const FW_CPoint& end,
  182.                                 const FW_PInk& ink,
  183.                                 const FW_PStyle& style)
  184. {
  185.     gc.GetRasterizer()->RenderLine(gc,
  186.                                     start, end,
  187.                                     FW_kFrame,
  188.                                     ink,
  189.                                     style);
  190. }
  191.  
  192. //----------------------------------------------------------------------------------------
  193. //    FW_CLineShape::GetBounds
  194. //----------------------------------------------------------------------------------------
  195.  
  196. void FW_CLineShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
  197. {
  198. FW_UNUSED(gc);
  199.  
  200.     rect.Set(fStart.x, fStart.y, fEnd.x, fEnd.y);
  201.     rect.Sort();
  202.     FW_CFixed halfPen = GetPenSize().Half();
  203.     rect.Inset(-halfPen, -halfPen);
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. //    FW_CLineShape::Transform
  208. //----------------------------------------------------------------------------------------
  209.  
  210. void FW_CLineShape::Transform(Environment *ev, ODTransform* transform)
  211. {
  212.     fStart.Transform(ev, transform);
  213.     fEnd.Transform(ev, transform);
  214. }
  215.  
  216. //----------------------------------------------------------------------------------------
  217. //    FW_CLineShape::InverseTransform
  218. //----------------------------------------------------------------------------------------
  219.  
  220. void FW_CLineShape::InverseTransform(Environment *ev, ODTransform* transform)
  221. {
  222.     fStart.InverseTransform(ev, transform);
  223.     fEnd.InverseTransform(ev, transform);
  224. }
  225.  
  226. //----------------------------------------------------------------------------------------
  227. //    FW_CLineShape::Inset
  228. //----------------------------------------------------------------------------------------
  229.  
  230. void FW_CLineShape::Inset(FW_CFixed x, FW_CFixed y)
  231. {
  232.     if (fStart.x > fEnd.x)
  233.     {
  234.         fStart.x += x;
  235.         fEnd.x -= x;
  236.     }
  237.     else if (fStart.x < fEnd.x)
  238.     {
  239.         fStart.x -= x;
  240.         fEnd.x += x;
  241.     } 
  242.     else
  243.     {
  244.         if (fStart.y < fEnd.y)
  245.         {
  246.             fStart.x -= x;
  247.             fEnd.x += x;
  248.         }
  249.         else
  250.         {
  251.             fStart.x += x;
  252.             fEnd.x -= x;
  253.         }
  254.     }
  255.  
  256.     if (fStart.y > fEnd.y)
  257.     {
  258.         fStart.y += y;
  259.         fEnd.y -= y;
  260.     }
  261.     else if (fStart.y < fEnd.y)
  262.     {
  263.         fStart.y -= y;
  264.         fEnd.y += y;
  265.     } 
  266.     else
  267.     {
  268.         if (fStart.x < fEnd.x)
  269.         {
  270.             fStart.y -= y;
  271.             fEnd.y += y;
  272.         }
  273.         else
  274.         {
  275.             fStart.y += y;
  276.             fEnd.y -= y;
  277.         }
  278.     }
  279. }
  280.  
  281. //----------------------------------------------------------------------------------------
  282. //    FW_CLineShape::MoveShape
  283. //----------------------------------------------------------------------------------------
  284.  
  285. void FW_CLineShape::MoveShape(FW_CFixed deltaX, FW_CFixed deltaY)
  286. {
  287.     fStart.x += deltaX;
  288.     fStart.y += deltaY;
  289.     fEnd.x += deltaX;
  290.     fEnd.y += deltaY;
  291. }
  292.  
  293. //----------------------------------------------------------------------------------------
  294. //    FW_CLineShape::MoveShapeTo
  295. //----------------------------------------------------------------------------------------
  296.  
  297. void FW_CLineShape::MoveShapeTo(FW_CFixed x, FW_CFixed y)
  298. {
  299.     fEnd.x += x - fStart.x;
  300.     fEnd.y += y - fStart.y;
  301.     fStart.x = x;
  302.     fStart.y = y;
  303. }
  304.  
  305. //----------------------------------------------------------------------------------------
  306. //    FW_CLineShape::HitTest
  307. //----------------------------------------------------------------------------------------
  308.  
  309. FW_Boolean FW_CLineShape::HitTest(FW_CGraphicContext& gc,
  310.                                   const FW_CPoint& test,
  311.                                   FW_CFixed tolerance) const
  312. {
  313.     if(fRenderVerb == FW_kNoRendering)
  314.         return FALSE;
  315.  
  316.     return ::FW_HitTestLine(fStart, fEnd, test, tolerance);
  317. }
  318.  
  319. //----------------------------------------------------------------------------------------
  320. //    FW_CLineShape::Copy
  321. //----------------------------------------------------------------------------------------
  322.  
  323. FW_CShape* FW_CLineShape::Copy() const
  324. {
  325.     return FW_NEW(FW_CLineShape, (*this));
  326. }
  327.  
  328. //----------------------------------------------------------------------------------------
  329. //    FW_CLineShape::GetGeometry
  330. //----------------------------------------------------------------------------------------
  331.  
  332. void FW_CLineShape::GetGeometry(FW_CPoint& start, FW_CPoint& end) const
  333. {
  334.     start = fStart;
  335.     end = fEnd;
  336. }
  337.  
  338.  
  339. //----------------------------------------------------------------------------------------
  340. //    FW_CLineShape::SetGeometry
  341. //----------------------------------------------------------------------------------------
  342.  
  343. void FW_CLineShape::SetGeometry(const FW_CPoint& start, const FW_CPoint& end)
  344. {
  345.     fStart = start;
  346.     fEnd = end;
  347. }
  348.  
  349. //----------------------------------------------------------------------------------------
  350. //    FW_CLineShape::Flatten
  351. //----------------------------------------------------------------------------------------
  352.  
  353. void FW_CLineShape::Flatten(FW_CWritableStream& archive) const
  354. {
  355.     FW_CShape::Flatten(archive);
  356.     
  357.     archive << fStart;
  358.     archive << fEnd;
  359. }
  360.  
  361. //----------------------------------------------------------------------------------------
  362. //    FW_CLineShape::Read
  363. //----------------------------------------------------------------------------------------
  364.  
  365. void* FW_CLineShape::Read(FW_CReadableStream& archive)
  366. {
  367.     return FW_NEW(FW_CLineShape, (archive));
  368. }
  369.  
  370.